<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Worklinkback extends Model
{
    protected $table='work_link_back';
    protected $primaryKey='id';

    public static function usersWorkLinkBack($users_id,$kfid,$back_platfrom)
    {
        $query = self::where("users_id",$users_id);
        if (!empty($kfid)) $query->where("kfid",$kfid);
        if (!empty($back_platfrom)) $query->where("back_platfrom",$back_platfrom);
        return $query->paginate(20);
    }

    public static function getWorkLinkBack($kfid)
    {
        return self::where("kfid",$kfid)->first();
    }

    public static function getWorkLinkBackLists($kfid)
    {
        return self::select("back_platfrom","assets_id","back_distinct")->where("kfid",$kfid)->get();
    }

    public static function getWorkLinkBackPlatfrom($kfid,$back_platfrom)
    {
        return self::select("kfid","assets_id","back_platfrom","submit_type","submit_rate","transform_target","other","other","assets_id","domain","submit_browser","submit_time","api_id","api_key","event_active")->where("kfid",$kfid)->where("back_platfrom",$back_platfrom)->first();
    }

    public static function indexSitePlatfromListsBack($kfid,$back_platfrom)
    {
        return self::select("assets_id","back_distinct","other")->where("kfid",$kfid)->where("back_platfrom",$back_platfrom)->first();
    }

    public static function getAllWorkLinkBack($kfid)
    {
        return self::select("back_platfrom","assets_id","transform_target","kfid")->where("kfid",$kfid)->get();
    }

    public static function recordSitePlatfromListsBack($kfid)
    {
        return self::select("back_platfrom","assets_id","transform_target","kfid")->whereIn("kfid",$kfid)->get();
    }

    public static function workLinkBackUpdate($kfid,$back_platfrom,$assets_id,$submit_rate,$transform_target,$submit_type,$event_active,$other,$submit_time,$submit_browser,$api_id,$api_key,$domain)
    {
        return self::where("kfid",$kfid)->where("back_platfrom",$back_platfrom)->update(["assets_id"=>$assets_id,"submit_rate"=>$submit_rate,"transform_target"=>$transform_target,"submit_type"=>$submit_type,"event_active"=>$event_active,"other"=>$other,"submit_time"=>$submit_time,"submit_browser"=>$submit_browser,"api_id"=>$api_id,"api_key"=>$api_key,"domain"=>$domain]);
    }

    public static function createWorkLinkBack($kfid,$back_platfrom,$assets_id,$back_distinct,$rate,$other,$transform_target)
    {
        return self::insert(["kfid"=>$kfid,"back_platfrom"=>$back_platfrom,"assets_id"=>$assets_id,"back_distinct"=>$back_distinct,"other"=>$other,"transform_target"=>$transform_target,"event_active"=>"press","created_at"=>time()]);
    }

    public static function siteListBackVivoUpdate($kfid,$back_platfrom,$assets_id,$other,$api_id,$api_key)
    {
        return self::where("kfid",$kfid)->where("back_platfrom",$back_platfrom)->update(["assets_id"=>$assets_id,"other"=>$other,"api_id"=>$api_id,"api_key"=>$api_key]);
    }

    public static function getLinkBackChat($kfid)
    {
        return self::where("kfid",$kfid)->where("event_active","chat")->first();
    }
}
